$(function(){
	var orgData = {};
	$.ajax({
		async : false,
		url : projectPath + "user/getCurrentUser.do",
		data : {},
		dataType : "json",
		success : function(data) {
			orgData = data;
			$('#orgSelect').val(orgData.orgname);
			$('#orgSelect').attr('data', orgData.orgcode);
		}
	});
	
	bindOrg2("orgSelect");
	
	bindDict("businessType","DM_XKXMLX","");
	
	var now = new Date();
	var dayStr = now.getDate() > 9 ? now.getDate() : '0' + now.getDate();
	var monStr = (now.getMonth() + 1) > 9 ? (now.getMonth() + 1) : '0' + (now.getMonth() + 1);
	var dateStr = now.getFullYear() + '-' + monStr + '-' + dayStr;
	$('#publishDate').attr('min', dateStr);
	$('#publishDate').val(dateStr);
});


function save(){
	var questionsData = $("#questionsForm").serializeObject();
	questionsData.orgCode = $('#orgSelect').attr("data");
	if(!check(questionsData)){
		return true;
	}
	
	$.ajax({ 
		method: 'post',
		url: basePath() + 'questions/save.do',
		data: JSON.stringify(questionsData),
		dataType: "json",
        contentType: "application/json",
		success: function(data){
			window.wxc.xcConfirm(data.info, window.wxc.xcConfirm.typeEnum.success, {
				onOk: function(){
					if(data.result == 1){
						parent.refreshData();//刷新数据
					} 
				}
			});
      	}
	});
	
}

function check(data){	
	var result = true;

	var mustStr = "title,content,businessType,replyContent,orgName,pubilshDate";
	
	var strMsg = "";
	var mustStrs = mustStr.split(',');
	for(var i=0; i<mustStrs.length; i++){
		var obj = $('[name="'+mustStrs[i]+'"]');
		if(obj.val() == ""){
			strMsg += obj.attr("placeholder") + "！<br />";
			result = false;
		}
	}
	
	if(strMsg != ""){
		window.wxc.xcConfirm(strMsg, window.wxc.xcConfirm.typeEnum.error);
	}
	
	return result;
}
